package cn.itcast.activemq.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;

public class TopicTest {
    public static void main(String[] args) {
        //创建spring容器
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext-topic.xml");
        //获取JmsTemplate
        JmsTemplate jmsTemplate = ac.getBean(JmsTemplate.class);
        //发送消息
        jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                MapMessage mm = session.createMapMessage();
                mm.setInt("id",1);
                mm.setString("name","王林代码敲完了你呢?");
                mm.setInt("age",20);
                return mm;
            }
        });
    }
}
